package com.three.controller;

import com.three.aop.LogAnotation;
import com.three.entity.Staff;
import com.three.service.StaffService;
import com.three.vo.R;
import com.three.vo.StaffVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController//@Controller+@ResponseBody
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffService staffService;
    @Autowired
    private HttpSession session;
    //登录验证
    @PostMapping("/login")
    //@LogAnotation("登陆验证")//日志
    public R loginByNameAndPwd(@RequestBody StaffVo staffVo){
        return staffService.loginByNameAndPwd(staffVo);
    }

    @GetMapping("/getStaffInfo")
    public R getStaffInfo(){
        Object staff = session.getAttribute("staff");
        return R.ok(staff);
    }

    @GetMapping("/logout")
    public R logout(){
        session.removeAttribute("staff");
        return R.ok();
    }
    //获取不是店长的所有人员工信息
    @GetMapping("/selectStaff")
    public R selectStaff(){
        return staffService.selectStaff();
    }

    //插叙你当前的登录者的全部信息，包含部门，角色，所在门店
    @GetMapping("/getStaffInfoAll11")
    public R getStaffInfo1(){
        return staffService.getStaffInfo11();
    }

    //根据deptid部门id查询该部该部门下的所有员工
    @GetMapping("/selectByDeptId")
    public R selectByDeptId(Integer deptid,Integer currentPage02,Integer pageSize02){
        return staffService.selectByDeptId(deptid,currentPage02,pageSize02);
    }

    @GetMapping("/getNowStaff")
    public R getNowStaff(){
        return staffService.getNowStaff();
    }

    //修改员工信息
    @PostMapping("/updateStaff")
    public R updateStaff(@RequestBody Staff staff){

        return staffService.updateStaff(staff);
    }
}
